package leetcode.templates.bits;

import java.util.List;

public class MaxBitsOps {

	// 把数组变成一个hash状态
	public int hash(int[][] board) {
		int ans = 0;
		int m = board.length, n = board[0].length;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				int cur = board[i][j];
				ans <<= 3;
				ans |= cur;
			}
		}
		return ans;
	}


	// 在状态curStat时，翻转index和邻接way的位置
	public int change(int curStat, int index, List<Integer> way) {
		curStat = opposite(curStat, index);
		for (int around : way) {
			curStat = opposite(curStat, around);
		}
		return curStat;
	}

	// num中index位1,0互换
	public int opposite(int num, int index) {
		int pos = 1 << index;
		if ((num & pos) == 0) {
			return num + pos;
		} else {
			return num - pos;
		}
	}




}
